const app = getApp(),
  api = getApp().api;
var is_loading = !1,
  is_no_more = !1,
  p = 1;

Page({
  data: {
    order_status: 3,
    order_list: [],
    latitude: '',
    longitude: '',
  },
  onLoad: function (t) {
    getApp().page.onLoad(this, t);
    var e = this;
    is_loading = is_no_more = !1, p = 1;
    this.getLocation();
  },
  //页面数据
  loadData: function () {
    let o = this;
    console.log(o.data);
    is_loading || is_no_more || (is_loading = !0, getApp().request({
      url: getApp().api.user.get_delivery_list,
      data: {
        order_status: o.data.order_status,
        page: p,
        nowlatitude: o.data.latitude,
        nowlongitude: o.data.longitude
      },
      success: function (t) {
        if (0 == t.code) {
          o.setData({
            user: t.data.user,
            state: t.data.user.delivery_office == 0 ? true : false,
            count: t.data.count
          }), 0 == t.data.list.length && (is_no_more = !0);
          if (p > 1) {
            o.data.order_list.push(...t.data.list);
            o.setData({
              order_list: o.data.order_list
            });
            console.log(o.data.order_list);
          } else {
            o.setData({
              order_list: t.data.list
            });
          }
        }
        p++;
      },
      complete: function () {
        is_loading = !1;
      }
    }));
  },
  //跳转页面
  goUrl: function (e) {
    var gopage = e.currentTarget.dataset.url;
    if (!gopage) {
      return;
    }
    getApp().core.navigateTo({
      url: gopage
    });
  },
  //获取定位经纬度
  getLocation: function () {
    let o = this;
    wx.getLocation({
      type: 'wgs84',
      success: (res) => {
        console.log(res);
        var latitude = res.latitude
        var longitude = res.longitude
        o.setData({
          latitude: latitude,
          longitude: longitude
        }), o.loadData();
      }

    })
  },
  // 进行拨打电话
  telShop: function (e) {
    var phone = e.currentTarget.dataset.phone;
    if (phone) {
      wx.makePhoneCall({
        phoneNumber: phone
      })
    } else {
      getApp().core.showModal({
        title: "拨打失败",
        content: "商家未绑定手机号",
        showCancel: !1
      });
    }
    console.log(e);
  },
  // 刷新页面数据
  loadSet: function () {
    p = 1;
    is_no_more = !1;
    this.loadData();
  },
  //下拉刷新
  onPullDownRefresh: function () {
    console.log('下拉刷新');
    getApp().page.onPullDownRefresh(this);
    this.loadSet();
  },
  // 上拉加载
  onReachBottom: function () {
    console.log('上拉加载');
    is_no_more || this.loadData();
  }
})
